<?php
/* 
 * class.grade.php
 * 我的城市首页-商家信息
 * @author samuel
 * @date 2009-05-23
 */
include_once 'class.mycityBase.php';
class mycity_grade extends mycityBase {
    private $seller_id;
    private $step;


    function  __construct($core) {
        parent::__construct();
        //参数处理
	    $this->step = $this->params['step'] ? strtolower(trim($core->params['step'])) : 'index';
	    $this->seller_id = $this->params['sid'] ? (int)$this->params['sid'] : 0;
	    $this->user_id = $this->params['uid'] ? (int)$this->params['uid'] : 1;
	    if(!$this->user_id){
		    $this->error = "用户ID不合法！";
		    $this->jumpError();
		    exit;
	    }
	    if(!$this->seller_id){
		    $this->error = "商家ID不合法！";
		    $this->jumpError();
		    exit;
	    }

        $run = "run_" . $this->step;
        
        //header("Content-type: text/vnd.wap.wml");
        $this->$run();
    }
    
    function run_index(){
        //WAP页面
	    //header("Content-type: text/vnd.wap.wml");
	    //TITLE
	    $page_title = "我的城市-商家评分";
	    $content = "";
	    $content .= "<a href='./mycity.php?act=sellerinfo&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."' alt='返回上级'>返回上级</a><br/>";
	    //评分列表 
	    $star_icon = "<img src='' />";
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=grade&amp;step=grade_do&amp;grade=5&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."' title='太棒了'>".$star_icon.$star_icon.$star_icon.$star_icon.$star_icon."</a><br/>";
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=grade&amp;step=grade_do&amp;grade=4&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."' title='还不错'>".$star_icon.$star_icon.$star_icon.$star_icon."</a><br/>";
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=grade&amp;step=grade_do&amp;grade=3&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."' title='一般般'>".$star_icon.$star_icon.$star_icon."</a><br/>";
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=grade&amp;step=grade_do&amp;grade=2&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."' title='烂'>".$star_icon.$star_icon."</a><br/>";
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=grade&amp;step=grade_do&amp;grade=1&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."' title='怎么还不倒闭'>".$star_icon."</a><br/><br/>";
	    
	    //查看好友评分
	    $content .= "<a href='".$_SERVER['PHP_SELF']."?act=grade&amp;step=friendsgrade&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."' alt='查看好友评分'>查看好友评分</a><br/><br/><br/>";
	    
	    
	
	    $content .= "<a href='./mycity.php?act=sellerinfo&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."' alt='返回上级'>返回上级</a><br/>";
	    $content .= "<a href='' alt='建议帮助'>建议帮助</a>";



	    $this->core->tpl->assign('content', $content);
	    $this->core->tpl->assign('page_title', $page_title);
	    $this->core->tpl->display('comm.wml');
    }
    
    function run_grade_do(){
        $page_title = "我的城市-商家评分";
    	$backurl = $_SERVER['PHP_SELF'] . '?act=sellerinfo&sid=' . $this->seller_id . '&uid=' . $this->user_id;
    	
        //判断是否已经评过分了
        $tag = $this->getSellerGrades($this->seller_id, $this->user_id, true);
        if($tag){
            $this->error = "对不起，您已经对该商家评过分了！";
            $this->jumpError("", $page_title, $backurl);
            exit;
        }
        
        $grade = $this->params['grade'];
        $grade = $grade ? (int)$grade : 0;
        $sql = "INSERT INTO `fun_seller_grade` SET `UserID`='".$this->user_id."', `SellerID`='".$this->seller_id."', `SellerGrade`='".$grade."', `SellerGradeAtTime`=now()";
        $res = $this->core->db->query($sql);
        $sql = "UPDATE `fun_seller` SET `SellerGrade`=`SellerGrade`+".$grade." WHERE `SellerID`='".$this->seller_id."'";
        $res = $this->core->db->query($sql);
        if($res){
            $content = "评分成功！";
        }else{
            $content = "评分失败！";
        }

    	$this->jumpPrompt($content, $page_title, $backurl);
    }
    
    function run_friendsgrade(){
        //WAP页面
	    //header("Content-type: text/vnd.wap.wml");
	    //TITLE
	    $page_title = "我的城市-商家评分";
	    $content = "";
	    $content .= "<a href='./mycity.php?act=grade&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."' alt='返回上级'>返回上级</a><br/>";
	    
	    //获取已验证好友列表
	    $friends = $this->getUserFriends($this->user_id);
	    if($friends){
	        foreach($friends as $friend){
	            $f_grade = $this->getSellerGrades($this->seller_id, $friend['UserFriendID']);
	            if(!$f_grade) continue;
                switch($f_grade['SellerGrade']){
                    case '5':
                        $grade_info = "太棒了";
                        break;
                    case '4':
                        $grade_info = "还不错";
                        break;
                    case '3':
                        $grade_info = "一般般";
                        break;
                    case '2':
                        $grade_info = "烂";
                        break;
                    case '1':
                        $grade_info = "怎么还不倒闭";
                        break;
                }
	            $content .= "<img src='' alt='图标' />".$friend['UserNickName']." ".$grade_info."<br/>";
	        }
	    }
	    
	    
	    
	    
	    
	    $content .= "<br/><br/>";
	    $content .= "<a href='./mycity.php?act=grade&amp;sid=".$this->seller_id."&amp;uid=".$this->user_id."' alt='返回上级'>返回上级</a><br/>";
	    $content .= "<a href='' alt='建议帮助'>建议帮助</a>";



	    $this->core->tpl->assign('content', $content);
	    $this->core->tpl->assign('page_title', $page_title);
	    $this->core->tpl->display('comm.wml');
    }
}


?>
